/**
 * 
 */
package com.maohi.software.tupuna.implementations;

import java.util.ArrayList;
import java.util.List;

import com.google.inject.Inject;
import com.maohi.software.arii.mvc.events.ModelEvent;
import com.maohi.software.arii.mvc.listeners.ModelListener;
import com.maohi.software.tupuna.interfaces.TupunaModel;

/**
 * @author heifara
 * 
 */
public class DefaultTupunaModel implements TupunaModel {

	private List<ModelListener> modelListeners;

	@Inject
	public DefaultTupunaModel() {
		this.modelListeners = new ArrayList<>();
	}

	@Override
	synchronized public void addModelListener(ModelListener aListener) {
		this.modelListeners.add(aListener);
	}

	protected void fireDataChangedEvent() {
		for (ModelListener iListener : this.modelListeners) {
			iListener.dataChanged(new ModelEvent(this));
		}
	}

	@Override
	public List<ModelListener> getModelListeners() {
		return this.modelListeners;
	}

	@Override
	synchronized public void removeModelListener(ModelListener aListener) {
		this.modelListeners.remove(aListener);
	}

}
